<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>跨境电商借卖平台</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="stylesheet" th:href="@{/res/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/res/css/global.css}">
    <script th:src="@{/res/layui/layui.js}"></script>
    <script th:src="@{/js/jquery-1.11.3.min.js}"></script>
    <script th:src="@{/myplugs/js/plugs.js}"></script>


    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
          integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css"
          integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"
            integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
            crossorigin="anonymous"></script>

    <style>
        #icon_person #icon_role #icon_menu #icon_para #icon_wallet #icon_check #icon_dict #icon_para #icon_users #icon_selluserInfo .icon {
            font-size: 20px;
            position: relative;
            top: 10%;
            text-align: center;
        }

    </style>
</head>

<body>
<div class="header">
    <div class="main">
        <a style="margin-left: 30px;line-height: 65px; color: white;font-size: 18px;text-decoration:none;">跨境电商借卖平台--借卖方</a>
        <div class="nav"></div>
        <div class="nav-user">
            <!-- 登入后的状态 -->
            <a class="avatar" href="javascript:toInfo()">
                <img th:src="@{/res/images/8.jpg}">
                <cite style="color: white;" th:text="${session.name}"></cite>
                <cite th:text="${session.id}" id="uid" hidden="hidden"></cite>
                <i style="color: white;" id="logout">退出</i>
            </a>
        </div>
    </div>
</div>

<div class="main fly-user-main layui-clear">
    <ul class="layui-nav layui-nav-tree layui-inline" id="bvo">

    </ul>

    <div class="site-tree-mobile layui-hide">
        <i class="layui-icon">&#xe602;</i>
    </div>
    <div class="site-mobile-shade"></div>

    <div class="fly-panel fly-panel-user">
        <div class="layui-tab layui-tab-brief" lay-filter="user">
            <div class="layui-tab-content"
                 style="padding-left: 20px;padding-top: 20px;padding-right: 80px;padding-bottom: 0px;overflow: hidden">
                <iframe src="" width="88%" style="border: none;" height="800" border="none"
                        name="right" id="first"></iframe>
            </div>
        </div>
    </div>
</div>
</div>
</body>

<script type="text/javascript">
    var uid = $("#uid").text();
    /*//从url得到uid
    var result=new Object();
    result=getParameter();
    var uid=result["uid"];*/

    //动态往url加载uid
    wallerUrl = "";
    $(function () {
        $.get(
            "/menu/selectMenu2",//获取菜单
            {type: 2},
            function (data) {
                let item = $("#bvo")
                for (let i = 0; i < data.length; i++) {//动态添加菜单栏
                    let a = data[i];
                    a.name = a.name.substring(4)
                    a.url = a.url + "?uid=" + uid;
                    if (a.status == 1) {//获取当前用户拥有菜单
                        if (a.name == "我的钱包") {
                            wallerUrl = a.url;
                            item.append("  <li class=\"layui-nav-item\"><a href=\"" + a.url + "\" target=\"right\"  id=\"wallet\"\n" +
                                "                                      style=\"font-size: 18px;text-decoration:none;\">" + a.name + " </a></li>")
                        } else {
                            item.append("  <li class=\"layui-nav-item\"><a href=\"" + a.url + "\" target=\"right\" \n" +
                                "                                      style=\"font-size: 18px;text-decoration:none;\">" + a.name + " </a></li>")
                        }
                    }

                }
            }
        )
        $("#first").attr("src", "/sellUserMes?uid=" + uid);
        wallet()
    })

    //解析url传值
    function getParameter() {
        var url = location.search;//获取url?后面的内容
        var result = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                result[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return result;
    }

    function wallet() {
        $.ajax({
            type: 'post',
            url: '/wallet/selectMyWalletByUid',
            data: {uid: uid},
            dataType: 'text',
            success: function (mydata) {
                if (mydata == "true") {
                    //跳转到钱包页面
                    $("#wallet").attr("href", wallerUrl);
                } else {
                    //跳转到钱包注册页面
                    $("#wallet").attr("href", "/registerWallet?uid=" + uid);
                }
            },
            error: function () {
                //跳转到钱包注册页面
                $("#wallet").attr("href", "/registerWallet?uid=" + uid);
            }
        })
    }


    $("#logout").click(function () {
        $.ajax({
            type: "post",
            url: "/login/logout",
            data: {},
            dataType: "text",
            success: function () {
                alert("登出成功!");
                window.location.href = "/login";
            },
            error: function () {
                alert("失败!");
            }
        })
    });


    // 跳转到个人中心
    function toInfo() {
        $('#first').attr('src', '/sellUserMes?uid=' + uid);
    }
</script>
</html>